package cn.itcast.ssm.controller;

import cn.itcast.ssm.service.IOrdersService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "3")int pageSize){
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageInfo", new PageInfo<>(ordersService.findAll(currentPage, pageSize), 3));
        mv.setViewName("orders-page-list");
        return mv;
    }

    @RequestMapping("/detail.do")
    public ModelAndView detail(String oid){
        ModelAndView mv = new ModelAndView();
        //查询订单数据
        mv.addObject("orders", ordersService.findById(oid));
        //订单详情页
        mv.setViewName("orders-show");
        return mv;
    }
}
